import { defineStore } from "pinia";
import { ref, reactive } from "vue";
import { handleGetUserInfo } from "@/api/user";
export const useUserStore = defineStore(
  "user",
  () => {
    const username = ref("admin");
    const token = ref("");
    const userInfo = ref({});
    const menuKeys = ref(['home'])

    const getUserInfo = async () => {
      const data = {
        username: username.value,
      };
      const res = await handleGetUserInfo(data);
    //   console.log(res);
      userInfo.value = res.data;
    };

    const clearUserInfo = () => {
      username.value = "";
      token.value = "";
      userInfo.value = {};
    };

    return {
      username,
      menuKeys,
      token,
      userInfo,
      getUserInfo,
      clearUserInfo,
    };
  },
  {
    persist: true,
  }
);
